package com.yunji.web.message;

import com.yunji.base.domain.FeedbackDO;
import com.yunji.cabinet.business.FeedbackBusiness;
import com.yunji.common.base.response.Response;
import com.yunji.common.base.response.ResponseHelper;
import com.yunji.common.model.dto.FeedbackDTO;
import com.yunji.common.model.params.FeedbackParam;
import com.yunji.common.model.vo.FeedbackExportVO;
import com.yunji.common.utils.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * @Project: yunji-coffee
 * @Package: com.yunji.web.message
 * @Title: FeedbackController
 * <p>
 * History:
 * Date                     Version     Author          Summary
 * ============================================================
 * 2024-10-29 18:07:48      V1.0        HuaAo       新建类
 */
@RestController
@Api(tags = "管理端-反馈管理")
@RequestMapping("/container/feedback")
public class FeedbackController {

    @Resource
    FeedbackBusiness business;

    @Resource
    protected HttpServletResponse response;

    @ApiOperation("反馈列表")
    @GetMapping("/list")
    public Response<List<FeedbackDO>> list(@Valid FeedbackParam param) {
        return ResponseHelper.successWithPage(business.searchList(param));
    }

    @ApiOperation("反馈导出")
    @PostMapping("/export")
    public void export(FeedbackParam param) {
        List<FeedbackExportVO> list = business.export(param);
        ExcelUtil<FeedbackExportVO> util = new ExcelUtil<>(FeedbackExportVO.class);
        util.exportExcel(response, list, "反馈列表");
    }

    @ApiOperation("处理反馈")
    @PostMapping("/handle")
    public Response<?> operate(@Valid @RequestBody FeedbackDTO dto) {
        return ResponseHelper.handle(business.handle(dto), "处理失败");
    }

    @ApiOperation("反馈详情")
    @GetMapping("/getInfo/{id}")
    public Response<?> getInfo(@PathVariable Long id) {
        return ResponseHelper.success(business.getInfo(id), "查询成功");
    }

    @ApiOperation("批量删除反馈")
    @DeleteMapping("/delete/{ids}")
    public Response<?> delete(@PathVariable List<Long> ids) {
        return ResponseHelper.handle(business.delete(ids), "删除失败");
    }

    /*------------------------------------------搜索栏----------------------------------------------------*/

    @ApiOperation("网点名称匹配搜索")
    @GetMapping("/searchSiteName")
    public Response<List<String>> searchSiteName(@RequestParam("siteName") String siteName) {
        return ResponseHelper.successWithPage(business.searchSiteName(siteName));
    }

    @ApiOperation("网点电话匹配搜索")
    @GetMapping("/searchSiteTel")
    public Response<List<String>> searchSiteTel(@RequestParam("siteTel") String siteTel) {
        return ResponseHelper.successWithPage(business.searchSiteTel(siteTel));
    }

    @ApiOperation("代理名称匹配搜索")
    @GetMapping("/searchAgentName")
    public Response<List<String>> searchAgentName(@RequestParam("agentName") String agentName) {
        return ResponseHelper.successWithPage(business.searchAgentName(agentName));
    }

}